package com.string;

import java.util.Arrays;

public class ReverseNums {
    public static void main(String[] args) {
//        int a=-514748365;
//        while (a!=0){
//            int t=a%10;
//            a=a/10;
//            System.out.print(t);
//        }
        int res = reverse(1147483649);
        System.out.print(res);

    }

    public static int reverse(int x) {
        int res = 0;
        int last = 0;
        while(x!=0) {
            //每次取末尾数字
            int tmp = x%10;
            last = res;
            res = res*10 + tmp;
            //判断整数溢出
            if(last != res/10)
            {
                return 0;
            }
            x /= 10;
        }
        return res;
    }
}
